<meta http-equiv='Content-Type' content='Type=text/html; charset=utf-8'>
<?php 
//$db = mysql_connect("localhost","admin","admin");
//mysql_select_db("kruny",$db);

require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
//$wpdb->show_errors(); // включит показ ошибок
global $wpdb;
$tbl_orders  = $wpdb->prefix . 'orderstorage';
//if (isset($_POST['p'])){
//		global $wpdb;
//		global $tableordername;
//		$inputData = array(
//                'product_name' => strip_tags($_POST['item_name_1']),
//                'product_cost' => strip_tags($_POST['item_price_1']),
//                'product_count' => strip_tags($_POST['itemCount']),
//                'product_count' => strip_tags($_POST['item_total_1']),
//                'total' => strip_tags($_POST['product_total']),
//                'coment' => strip_tags($_POST['product_coment']),
//		'fio' => strip_tags($_POST['field_fio']),
//		'phone' => strip_tags($_POST['field_phone']),
//		'mail' => strip_tags($_POST['field_mail']),
//		'adress' =>strip_tags($_POST['adress']),
//		'status' => strip_tags($_POST['status'])
//		);
//		// Добавляем новый заказ в базу	
//		$wpdb->insert( $tableordername, $inputData );
//		$admin_email = get_option('admin_email');
////		$message = $inputData;
////		$user_mail = strip_tags($_POST['field_mail']);
////		wp_mail($admin_email, 'Поступило нове замовлення', $message); 
////		$headers = 'Від: '.strip_tags($_POST['field_mail']).' '.strip_tags($_POST['field_mail'])."\r\n";
////		wp_mail($user_mail, 'Mixer.com.ua | Ваше замовлення',$message, $headers);
//		
//		echo "ready";
//	
//              
//}
$dt=date('Y-m-d');
$count = $_GET['itemCount']; 
 for ($i = 1; $i <= $count; $i++) { 
     $product_name = strip_tags($_GET["item_name_".$i]);
     $product_cost = $_GET["item_price_".$i];
     $product_count = strip_tags($_GET["item_quantity_".$i]);
     $product_total = $_GET["item_price_".$i]*$_GET["item_quantity_".$i];
     $inputData = array(
         'product_name' =>$product_name,
         'product_cost' =>$product_cost,
         'product_count' =>$product_count,
         'product_total' => $product_total,
         'order_date' => $dt,
         'product_coment' => $_GET['formcomment'],
         'customer_name' => $_GET['formname'],
         'email' => $_GET['formemail'],
         'adress' => $_GET['formadress'],
         'phone' => $_GET['formphone'],
         'status' => 'new'
         );
$wpdb->insert( $tbl_orders, $inputData );
 }
 ?>

<script>
    window.location = "<?php bloginfo('siteurl');?>";
</script>

